LOG_FILE=/root/a.log
MAIL_GROUP="iscongyang@qq.com iscongyang@163.com 116340667@qq.com"
function CheckUrl()
{
    failcount=0
    for ((i=0;i<2;i++))
    do
        wget -T 3 --tries=1 --spider $1 >/dev/null 2>&1
        if [ $? -ne 0 ]
        then
            let failcount+=1;
        else
            break
        fi
    done
    return $failcount
}
function MAIL()
{
    local SUBJECT_CONTENT=$1
    for MAIL_USER in `echo $MAIL_GROUP`
    do
        mail -s "${SUBJECT_CONTENT}" $MAIL_USER <$LOG_FILE
    done
}
function sendMsg()
{
    if [ $1 -ge 1 ]
    then
        RETVAL=1
        NOW_TIME=`date +"%Y-%m-%d %H:%M:%S"`
        SUBJECT_CONTENT="http://$2 网站有问题,现在时间是: ${NOW_TIME}"
        echo -e "$SUBJECT_CONTENT"|tee $LOG_FILE
        MAIL $SUBJECT_CONTENT
    else
        echo "$2 is ok"
        RETVAL=0
    fi
    return $RETVAL
}
main()
{
    urls=( https://www.baid.com )
    for((i=0;i<${#urls[*]};i++))
    do
        CheckUrl ${urls[i]}
        sendMsg $? ${urls[i]}
    done
}
main